package com.cat.dataStructure;

import java.util.HashMap;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/count-number-of-bad-pairs/description/
 * @create 2025/8/14 11:14
 * @since JDK17
 */

public class Solution06 {
    static HashMap<Integer, Integer> map = new HashMap<>();
    public long countBadPairs(int[] nums) {
        long ans = 0;
        int n = nums.length, cnt;
        map.clear();
        for (int i = 0, t; i < n; i++) {
            t = nums[i] - i;
            cnt = map.getOrDefault(t, 0);
            ans += i - cnt;
            map.put(t, cnt + 1);
        }
        return ans;
    }
}
